package org.example.util;

import org.example.model.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    private Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    /**
     * 异常处理
     */
    @ExceptionHandler(Exception.class)
    public Result globalException(Exception e) {
        Result commonResult = new Result(500,"系统忙:"+e.getMessage(),null);
        logger.info("Exception : "+e.getMessage());//向日志文件打印信息
        e.printStackTrace();
        return commonResult;//向前端用户响应信息
    }
}
